package com.gz.rabbitmq.simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("47.98.235.94");
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");
        connectionFactory.setVirtualHost("demo");
        connectionFactory.setPort(5672);

        Connection connection = connectionFactory.newConnection();

        Channel channel = connection.createChannel();

        //                            队列名称           是否持久化     是否独占链接     是否自动删除     其他参数
        channel.queueDeclare("simple_demo", true, false, false, null);

        channel.basicPublish("", "simple_demo", null, "第一次测试".getBytes());

        channel.close();
        connection.close();
    }
}
